﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using Extensil.Common.CategoryHandler.Discovery;

namespace Extensil.Common.CategoryHandler
{
    public class CategorySection : ConfigurationSection
    {
        public static CategorySection GetConfig()
        {
            return (CategorySection)System.Configuration.ConfigurationManager.GetSection("CategorySection") ?? new CategorySection();
        }
        [ConfigurationProperty("CategoryHandlers")]
        [ConfigurationCollection(typeof(PluginHandlers), AddItemName = "CategoryHandler")]
        public PluginHandlers CategoryHandlers
        {
            get
            {
                object o = this["CategoryHandlers"];
                return o as PluginHandlers;
            }
        }
        [ConfigurationProperty("Discovery")]
        [ConfigurationCollection(typeof(DiscoverySection), AddItemName = "Probe")]
        public DiscoverySection DiscoverySection
        {
            get
            {
                object o = this["Discovery"];
                return o as DiscoverySection;
            }
        }
        [ConfigurationProperty("ProbeHandlers")]
        [ConfigurationCollection(typeof(PluginHandlers), AddItemName = "ProbeHandler")]
        public PluginHandlers ProbeHandlers
        {
            get
            {
                object o = this["ProbeHandlers"];
                return o as PluginHandlers;
            }
        }
        [System.Configuration.ConfigurationProperty("rootFolder")]
        public string RootFolder
        {
            get
            {
                return (string)this["rootFolder"];
            }
        }
        public bool IsFirstTime
        {
            get
            {
                return (FirstTime.ToLower() == "yes" ||
                    FirstTime.ToLower() == "y" ||
                    FirstTime.ToLower() == "true" ||
                    FirstTime.ToLower() == "on"
                    );
            }
            set
            {
                this.FirstTime = value ? "yes" : "no";
            }
        }
        [ConfigurationProperty("isFirstTime", IsRequired = false)]
        public string FirstTime
        {
            get
            {
                return base["isFirstTime"] as String;
            }
            set
            {
                base["isFirstTime"] = value;
            }
        }
        
        
    }
}
